var express = require('express');
// var webpackDevMiddleware = require("webpack-dev-middleware");
var WebpackDevServer = require("webpack-dev-server/lib/Server");
var webpack = require('webpack');
var webpackConfig = require('./webpack.dev.config');

var port = process.env.NODE_PORT || 8080;

var app = express();
var compiler = webpack(webpackConfig);

var server = new WebpackDevServer(compiler, {
    publicPath: "",//虚拟目录，脚本所在文件夹，与output.publicPath一致，与页面使用一致
    stats: { colors: true },
    port: port,
    historyApiFallback: true,
    hot: true,
    headers: {'Access-Control-Allow-Origin': '*'},
    disableHostCheck: true,
    setup: function(app){
        app.use(function(req, res, next){
            // console.log(`Using middleware for ${req.url}`);
            next();
        })
    }
})

server.listen(port, function (err, result) {
    if (err) {
        console.log(err);
    }
    console.log(`App is now running on port :127.0.0.1:${port}`);
});
